﻿Imports System.Web.Script.Serialization
Imports System.Data.SqlTypes
Imports sonicERPinfo
Imports sonicERPDAL

Partial Public Class WebForm1
    Inherits System.Web.UI.Page
    Dim util As New Util
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            getltdbox()
        End If
    End Sub

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click

        util.excel()

    End Sub

    Protected Sub Button2_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button2.Click
        util.xml()
    End Sub

    Protected Sub Button3_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button3.Click
        Dim texto As String = ""
        texto += "<script language='javascript'>" & vbCrLf & _
        " var teste = confirm('Click em ok para outra messagem')" & vbCrLf & _
       "if(teste)" & vbCrLf & _
      "alert('vc clickou em ok')" & vbCrLf & _
         "</script>"

        Page.ClientScript.RegisterClientScriptBlock(Me.GetType(), "cliente", texto)



    End Sub

    Protected Sub Button4_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button4.Click
        util.idade()

    End Sub

    Protected Sub Button5_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button5.Click
        Dim dal As New ClienteDAL
        Dim entidade As New Tabelainfo
        entidade.cliente.nomecliente = "rog"
        Dim dv As DataView = dal.getlista(entidade)
        Dim dt As DataTable = dv.ToTable()
        util.imprimir(dt)


        ''Dim javascript As String = "<script language ='javascript'>"
        ''javascript += " window.open('Imprimir.aspx', '', 'letf=0,top=0,width=900px,height=900px,toolbar=0,scrollbars=1,status=0');"
        ''javascript += " </script>"
        ''Page.ClientScript.RegisterClientScriptBlock(Me.GetType(), "imprimir", javascript)

    End Sub

    Public Sub getltdbox()
        Dim dal As New UsuarioDAL
        ltbusuariohistorco.DataSource = dal.getusuario_historico
        ltbusuariohistorco.DataTextField = "nome"
        ltbusuariohistorco.DataValueField = "id"
        ltbusuariohistorco.DataBind()
    End Sub
    Public Sub getgridview()
        Dim dal As New UsuarioDAL
        Dim valor As String = ""
        Dim i As Integer = 0
        For Each item As ListItem In ltbusuariohistorco.Items
            If item.Selected Then
                i = 0
                Exit For
            Else
                i += 1
            End If
        Next
        If i > 0 Then
            Throw New Exception("Selecione um Dado")
        End If


        For Each item As ListItem In ltbusuariohistorco.Items
            If item.Selected Then
                item.Value.Trim()
                valor += item.Value + ","
            End If

        Next
        If Not valor.Length = 0 Then

            valor = valor.Remove(valor.Length - 1, 1)
        End If

        gdvusuario.DataSource = dal.getusuario_historico1(valor)
        gdvusuario.DataBind()

    End Sub

    Protected Sub Button6_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button6.Click
        Try

            getgridview()

        Catch ex As Exception
            Response.Write(ex.Message)
        End Try
    End Sub
End Class